home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / itrns211.zip / SRC / LANG.C < prev    next >
C/C++ Source or Header  |  1991-10-13  |  5KB  |  181 lines

  1. /*
  2.  *========================================================================== 
  3.  * Copyright 1991 Avinash Chopde, All Rights Reserved.
  4.  *
  5.  * Permission to use, copy, modify and distribute this software and its
  6.  * documentation for any purpose is hereby granted without fee, provided that
  7.  * the above copyright notice appear in all copies and that both that
  8.  * copyright notice and this permission notice appear in supporting
  9.  * documentation, and that the name of Avinash Chopde not be used in
  10.  * advertising or publicity pertaining to distribution of the software
  11.  * without specific, written prior permission.
  12.  * Avinash Chopde makes no representations about the suitability of this
  13.  * software for any purpose.
  14.  * It is provided "as is" without express or implied warranty.
  15.  *
  16.  * AVINASH CHOPDE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  17.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  18.  * IN NO EVENT SHALL AVINASH CHOPDE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  19.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  20.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  21.  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  22.  * OF THIS SOFTWARE.
  23.  *
  24.  * Author:  Avinash Chopde, 1991
  25.  *        C2 Colonial Drive #4, Andover, MA 01810, USA.
  26.  *
  27.  */
  28.  
  29. static char S_RCSID[] = "$Header: e:/itrans/src/rcs/lang.c 1.3 91/10/13 16:50:51 avinash Exp $";
  30.  
  31. #include "itrans.h"
  32.  
  33. /* =================================================================== */
  34. void init_langs(lang_t *l, int num)
  35. {
  36.     int i;
  37.     for (i = 0; i < num; i ++) {
  38.  
  39.     null_lang(l + i);
  40.  
  41.     l[i].langno = i + ILANG_TOK;
  42.     switch(i + ILANG_TOK) {
  43.     case MARATHI_TOK:
  44.         l[i].name = "marathi";
  45.         break;
  46.     case HINDI_TOK:
  47.         l[i].name = "hindi";
  48.         break;
  49.     case ORIYA_TOK:
  50.         l[i].name = "oriya";
  51.         break;
  52.     case KANNADA_TOK:
  53.         l[i].name = "kannda";
  54.         break;
  55.     case SANSKRIT_TOK:
  56.         l[i].name = "sanskrit";
  57.         break;
  58.     case TAMIL_TOK:
  59.         l[i].name = "tamil";
  60.         break;
  61.     case BENGALI_TOK:
  62.         l[i].name = "bengali";
  63.         break;
  64.     case TELUGU_TOK:
  65.         l[i].name = "telugu";
  66.         break;
  67.     case MALAYALAM_TOK:
  68.         l[i].name = "malyalam";
  69.         break;
  70.     case GUJARATI_TOK:
  71.         l[i].name = "gujarati";
  72.         break;
  73.  
  74.     case ILANG_TOK:
  75.     default:
  76.         l[i].name = "default indian language";
  77.         break;
  78.     }
  79.     }
  80. }
  81. /* =================================================================== */
  82. void null_lang(lang_t *l)
  83. {
  84.     l->curr_ifmname = NULL;
  85.     l->curr_fontcmd = NULL;
  86.     l->curr_font = NULL;
  87. }
  88. /* =================================================================== */
  89. void clear_lang(lang_t *l)
  90. {
  91.     if (l->curr_ifmname) free(l->curr_ifmname);
  92.     if (l->curr_fontcmd) free(l->curr_fontcmd);
  93.  
  94.     /* don't free font (it is kept in allfonts also), just make it NULL */
  95.  
  96.     null_lang(l);
  97. }
  98. /* =================================================================== */
  99. /* cmd is of the form: "\XXXifm=YYY"
  100.  * first of all, the ifm file is searched for, and if not found, is
  101.  * loaded in.
  102.  * Then, the language structure is filled in.
  103.  */
  104. int find_load_ifm(lang_t* l, allfonts_t allf, char ifmtok[])
  105. {
  106.     char name[NAMELEN];
  107.     char *eqp;
  108.     int s, fnum;
  109.     font_t* ff;
  110.     
  111.     eqp = strchr(ifmtok, '=');
  112.     if (eqp == NULL) {
  113.         fprintf(stderr, "Illegal Indian IFM name line: %s\n", ifmtok);
  114.         return FALSE;
  115.     }
  116.  
  117.     eqp ++;
  118.     sprintf(name, "%s", eqp); /* to eat up all white space around it..*/
  119.  
  120.     if (strlen(name) < 1) {
  121.     if (G_verbose > 1) fprintf(stderr, "Null IFM statement (line %d) -- ignored\n",
  122.         G_lineno);
  123.     return FALSE;
  124.  
  125.     }
  126.  
  127.     if (chk_ext(name, ".ifm")) { /* missing .ifm, or wrong extension..*/
  128.         strcat(name, ".ifm");
  129.     }
  130.  
  131.     ff = find_font(allf, name);
  132.     if (!ff) {
  133.  
  134.         if (G_verbose > 0) fprintf(stderr, "Loading IFM file %s\n", name);
  135.  
  136.         /* allocate space for a single font.. */
  137.  
  138.         ff = (font_t*) malloc (sizeof(*ff));
  139.         init_font(ff);
  140.  
  141.         s = fillup_font(ff, name);
  142.  
  143.         if (!s) {
  144.          fprintf(stderr, "Error: fillup font error (fill up from %s)\n", name);
  145.          free(ff);
  146.          return FALSE;
  147.         }
  148.  
  149.     /* stuff it in the array of IFM files.... */
  150.     s = 0;
  151.     while (allf[s]) s++; 
  152.     if (s >= FONTS_MAX) {
  153.         fprintf(stderr, "Warning: cannot load in any more IFM files, will reuse previous location...\n");
  154.         fprintf(stderr, "(Max IFM files is %d, Current Line is %d, Loading %s)\n", 
  155.                 FONTS_MAX, G_lineno, name);
  156.         s--;
  157.         free(allf[s]);
  158.     }
  159.     allf[s] = ff;
  160.  
  161. #ifdef DEBUG
  162.         fprintf(stderr, "successfully loaded ifm: %s at loc %d\n", name, s);
  163. #endif /* DEBUG*/
  164.     } else {
  165.         if (G_verbose > 0) fprintf(stderr, "IFM  file %s already loaded.\n", name);
  166.     }
  167.  
  168.     l->curr_font = ff;
  169.  
  170.     if (l->curr_ifmname) free(l->curr_ifmname);
  171.  
  172.     eqp = strrchr(name, DIRSEP);
  173.     if (!eqp) eqp = name;
  174.     else eqp++;
  175.     l->curr_ifmname = (char*) malloc( sizeof(char) * (strlen(eqp) + 1));
  176.     strcpy(l->curr_ifmname, eqp);
  177.  
  178.     return TRUE;
  179. }
  180. /* =================================================================== */
  181.